﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;
using FrameWork;
using FrameWork.Components;
using FrameWork.WebControls;

namespace FrameWork.web.Module.ITMS.KnowledgeBase.KBQuery
{
    public partial class CatIndex : System.Web.UI.Page
    {
        public string TableSink = "";

        protected void Page_Load(object sender, EventArgs e)
        {

            TableSink = "blue";//Common.TableSink;
            OutJs();
        }

        private void OutJs()
        {
            int TotalRecord = 0;
            string strLink = "";
            int intCount = 0;
            QueryParam qp = new QueryParam();
            qp.Where = "Where K_Delete=0";
            qp.Orderfld = "K_Level,K_ShowOrder";
            qp.OrderType = 0;
            ArrayList lst = BusinessFacade.its_KnowledgeBaseKindList(qp, out TotalRecord);
            StringBuilder strSB = new StringBuilder();

            strSB.Append("<script language='JavaScript'>\n");
            strSB.Append("Fold_id='';\n");

            strSB.Append("treeRoot = gFld(\"mainbody\", \"知识库\", \"Default.aspx\")\n");

            foreach (its_KnowledgeBaseKind x in lst)
            {
                intCount = intCount + 1;
                strLink = "Default.aspx?KID=" + x.KID.ToString();
                if (x.K_Level == 1)
                {
                    if (x.K_ChildCount == 0)
                    {

                        strSB.AppendFormat("insDoc(treeRoot,gLnk(\"mainbody\",\"{0}\",\"{1}\"))\n", Common.ReplaceJs(x.K_KName), strLink);
                    }
                    else
                    {
                        strSB.AppendFormat("N{0}=insFld(treeRoot,gFld(\"mainbody\",\"{1}\",\"{2}\"))\n", x.KID, Common.ReplaceJs(x.K_KName), strLink);
                    }
                }
                else
                {
                    if (x.K_ChildCount == 0)
                    {
                        strSB.AppendFormat("insDoc(N{0},gLnk(\"mainbody\",\"{1}\",\"{2}\"))\n", x.K_ParentID, Common.ReplaceJs(x.K_KName), strLink);
                    }
                    else
                    {
                        strSB.AppendFormat("N{0}=insFld(N{1},gFld(\"mainbody\",\"{2}\",\"{3}\"))\n", x.KID, x.K_ParentID, Common.ReplaceJs(x.K_KName), strLink);
                    }
                }

            }

            strSB.Append("	initializeDocument();\n");
            strSB.Append("</script>\n");
            ShowScript.Text = strSB.ToString();
        }

    }
}
